package cn.tedu.sp04.order.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    //取消订单id获取订单
    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        Order order = orderService.getOrder(orderId);
        return JsonResult.ok().data(order);
    }
    //添加订单，demo演示
    @GetMapping("/")
    public JsonResult<?> addOrder(){
        Order order = new Order(
                         "5s8et86g4d89s",
                    new User(8,"用户8","密码8"),
        Arrays.asList(new Item[]{
                new Item(1,"aaa",1),
                new Item(3,"sss",3),
                new Item(4,"ttt",6),
                new Item(5,"fff",5),
                new Item(6,"bbb",4),
        }));
        orderService.addOrder(order);
    return JsonResult.ok().msg("添加订单成功");
    }

}
